import 'package:flutter/material.dart';

import 'package:flutter_hf/provider/provider_util.dart';
import 'package:flutter_hf/router/unit_router.dart';
import 'package:provider/provider.dart';
import 'package:xr_base/dimens.dart';
import 'package:xr_base/image_constants.dart';
import 'package:xr_base/view_util.dart';

import 'data/user_data.dart';
import 'discover/discover_page.dart';
import 'home/home_page.dart';
import 'message/message_page.dart';
import 'mine/mine_page.dart';

class AppPage extends StatefulWidget {
  const AppPage({Key? key}) : super(key: key);

  @override
  _AppPageState createState() => _AppPageState();
}

class _AppPageState extends State<AppPage> {
  int currentIndex = 0;
  final List _pageList = [HomePage(), DiscoverPage(), MessagePage(), MinePage()];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    /// 判断是否登录
    UserData().init();
  }

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: providers,
      child: MaterialApp(
        home: Scaffold(
          body: _pageList[currentIndex],
          bottomNavigationBar: BottomNavigationBar(
            type: BottomNavigationBarType.fixed,
            currentIndex: currentIndex,
            onTap: (int index) {
              setState(() {
                currentIndex = index;
              });
            },
            items: [
              BottomNavigationBarItem(
                icon: localImage(ImageConstants.ico_home_gre_nornal, width: Dimens.dn_25, height: Dimens.dn_25),
                label: "首页",
                activeIcon:
                    localImage(ImageConstants.ico_home_gre_active, width: Dimens.dn_25, height: Dimens.dn_25),
              ),
              BottomNavigationBarItem(
                icon: localImage(ImageConstants.ico_faxian_grey_normal, width: Dimens.dn_25, height: Dimens.dn_25),
                label: '发现',
                activeIcon:
                    localImage(ImageConstants.ico_faxian_grey_active, width: Dimens.dn_25, height: Dimens.dn_25),
              ),
              BottomNavigationBarItem(
                icon: localImage(ImageConstants.ico_xiaoxi_normal, width: Dimens.dn_25, height: Dimens.dn_25),
                label: '消息',
                activeIcon: localImage(ImageConstants.ico_xiaoxi_active, width: Dimens.dn_25, height: Dimens.dn_25),
              ),
              BottomNavigationBarItem(
                icon: localImage(ImageConstants.ico_wode_normal, width: Dimens.dn_25, height: Dimens.dn_25),
                label: '我的',
                activeIcon: localImage(ImageConstants.ico_wode_active, width: Dimens.dn_25, height: Dimens.dn_25),
              ),
            ],
          ),
        ),
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        onGenerateRoute: UnitRouter.generateRoute,
      ),
    );
  }
}
